package com.study.ssm.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author zhoujunlin
 * @date 2023年08月07日 16:27
 * @desc
 */
@Component
public class StudentBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        System.out.println("=========>StudentBeanFactoryPostProcessor.postProcessBeanFactory");

        BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) configurableListableBeanFactory;

        GenericBeanDefinition studentBeanDefinition = new GenericBeanDefinition();
        studentBeanDefinition.setBeanClass(Student.class);
        
        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.add("name", "test");
        mutablePropertyValues.add("age", 30);
        studentBeanDefinition.setPropertyValues(mutablePropertyValues);

        beanDefinitionRegistry.registerBeanDefinition("student", studentBeanDefinition);
    }
}
